/* 
 * File:   main.cpp
 * Author: f.baumeister
 *
 * 
 * Created on 16. April 2013, 16:50
 */

#include <cstdlib>
#include <iostream>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
  int myServerSocket = socket(AF_INET,SOCK_STREAM,0);
  int clientSocket;
  socklen_t len;
  char data[64];
  struct sockaddr_in server;
  struct sockaddr_in client;
  
  memset( &server, 0, sizeof (server));
  server.sin_family=AF_INET;
  //Alle ip's gueltig
  server.sin_addr.s_addr=htonl(INADDR_ANY);
  //Horche auf Port 61991
  server.sin_port=htons(61991);
  
  if(myServerSocket, (sockaddr*)&server,sizeof(server)<0){
      cout << "Fehler beim Binden\n" <<endl;
  }
  if(listen(myServerSocket,5)==-1){
      cout << "Fehler beim Listen\n"  <<endl;
  }
  
  while(true){
      len = sizeof(client);
      clientSocket = accept(myServerSocket, (sockaddr*)&client, &len);
      if(clientSocket<0){
           cout << "Fehler beim Accept\n" <<endl;
           continue;
      }
      recv(myServerSocket,data,64,0);
      close(myServerSocket);
      
      
  }
  
  
  
  
  return 0;
}

